package com.huli.controller;

import cn.hutool.core.lang.Assert;
import com.huli.domain.Comment;
import com.huli.domain.Reply;
import com.huli.service.CommentService;
import com.huli.service.ReplyService;
import com.huli.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
//@RequestMapping("comment")
@Api(tags = "评论接口")
public class CommentController {

    @Autowired
    private CommentService commentService;

    @Autowired
    private ReplyService replyService;

    @ApiOperation("新增评论")
    @PostMapping("newComment")
    public Result newComment(@RequestBody Comment comment) {
        boolean b = commentService.save(comment);
        Assert.isTrue(b, "评论失败!");

        return Result.successResult(null);
    }

    @ApiOperation("新增回复")
    @PostMapping("reply")
    public Result reply(@RequestBody Reply reply) {
        boolean b = replyService.save(reply);
        Assert.isTrue(b,"回复失败");

        return Result.successResult(null);
    }


}
